#include "mytimer.h"

MyTimer::MyTimer( QObject* parent ) : QObject( parent ) {
    time  = new QTime( 0, 0, 0 );
    timer = new QTimer;
    connect( timer, &QTimer::timeout, this, &MyTimer::updateTime );
}

void MyTimer::start( const int& ms ) {
    time->setHMS( 0, 0, 0 );  //每次开始的时候复位
    timing_cycle = ms;
    timer->start( timing_cycle );
}

void MyTimer::stop() {

    timer->stop();
}

QString MyTimer::getTimeStr() {
    return time->toString( "hh:mm:ss" );
}

void MyTimer::updateTime() {
    *time = time->addMSecs( timing_cycle );
}
